<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: shipping_status.php 108 2013-09-21 12:07:26Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 108 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-21 12:07:26 +0000 (Sat, 21 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

require('includes/application_top.php');

switch ($_GET['action']) {
	case 'insert':
	case 'save':
		$shipping_status_id = $_GET['oID'];
		
		$languages = get_languages();
		for($i = 0, $n = sizeof($languages); $i < $n; $i++) {
			$shipping_status_name_array = $_POST['shipping_status_name'];
			$language_id = $languages[$i]['id'];
			
			$sql_data_array = array('shipping_status_name' => $shipping_status_name_array[$language_id]);
			
			if($_GET['action'] == 'insert') {
				if(!not_null($shipping_status_id)) {
					$next_id = $db->db_query("SELECT max(shipping_status_id) AS shipping_status_id FROM ".TABLE_SHIPPING_STATUS."");
					$shipping_status_id = $next_id->fields['shipping_status_id'] + 1;
				}
				
				$insert_sql_data = array('shipping_status_id' => $shipping_status_id,
										'language_id' => $language_id);
				$sql_data_array = array_merge($sql_data_array, $insert_sql_data);
				$db->db_perform(TABLE_SHIPPING_STATUS, $sql_data_array);
				
			} elseif ($_GET['action'] == 'save')
				$db->db_perform(TABLE_SHIPPING_STATUS, $sql_data_array, 'update', "shipping_status_id = '".$shipping_status_id."' AND language_id = '".$language_id."'");
		}
		
		if ($shipping_status_image = &try_upload('shipping_status_image', DIR_FS_CATALOG.DIR_WS_IMAGES))
			$db->db_query("UPDATE ".TABLE_SHIPPING_STATUS." SET shipping_status_image = '".$shipping_status_image->filename."' WHERE shipping_status_id = '".$shipping_status_id."'");

		
		if($_POST['default'] == 'on')
			$db->db_query("UPDATE ".TABLE_CONFIGURATION." SET configuration_value = '".$shipping_status_id."' WHERE configuration_key = 'DEFAULT_SHIPPING_STATUS_ID'");
		
		redirect(href_link(FILENAME_SHIPPING_STATUS,'oID='.$shipping_status_id.(isset($_GET['page']) ? '&page='.$_GET['page'] : '')));
		break;
	
	case 'deleteconfirm':
		$oID = $_GET['oID'];
		
		if(DEFAULT_SHIPPING_STATUS_ID == $oID)
			$db->db_query("UPDATE ".TABLE_CONFIGURATION." SET configuration_value = '' WHERE configuration_key = 'DEFAULT_SHIPPING_STATUS_ID'");
		
		$db->db_query("DELETE FROM ".TABLE_SHIPPING_STATUS." WHERE shipping_status_id = '".$oID."'");
		
		redirect(href_link(FILENAME_SHIPPING_STATUS, (isset($_GET['page']) ? 'page='.$_GET['page'] : '')));
		break;
	
	case 'delete':
		$oID = $_GET['oID'];

		$remove_status = true;
		if ($oID == DEFAULT_SHIPPING_STATUS_ID) {
			$remove_status = false;
			$message_stack->add(ERROR_REMOVE_DEFAULT_SHIPPING_STATUS, 'error');
		}
		break;
}
require(DIR_WS_INCLUDES.'metatag.php');
?>
</head>
<body>
<?php require(DIR_WS_INCLUDES.'header.php'); ?>
<div id="wrapper">
<table class="outerTable" cellpadding="0" cellspacing="0">
  <tr>
    <td class="columnLeft2" width="<?php echo BOX_WIDTH; ?>" valign="top">
		<?php require(DIR_WS_INCLUDES.'column_left.php'); ?>
	</td>
    <td class="boxCenter" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="0">
      <tr>
        <td>
			<table class="table_pageHeading" border="0" width="100%" cellspacing="0" cellpadding="0">
		    	<tr>
			     <td class="pageHeading">
			        <?php echo HEADING_TITLE; ?>
			     </td>
			   </tr>
			</table>
        </td>
      </tr>
      <tr>
        <td valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td valign="top"><table width="100%" cellspacing="0" cellpadding="0" class="dataTable">
              <tr class="dataTableHeadingRow">
              <td class="dataTableHeadingContent" width="1"><?php echo TABLE_HEADING_SHIPPING_STATUS; ?></td>
                <td class="dataTableHeadingContent" width="100%">&nbsp;</td>
                <td class="dataTableHeadingContent last" align="right"><?php echo TABLE_HEADING_ACTION; ?>&nbsp;</td>
              </tr>
			<?php
			  $sql = "SELECT 
			  				shipping_status_id, 
			  				shipping_status_name,
			  				shipping_status_image 
			  			FROM 
			  				".TABLE_SHIPPING_STATUS." 
			  			WHERE 
			  				language_id = '".$_SESSION['languages_id']."' 
			  			ORDER BY 
			  				shipping_status_id";
			  
			  $query = page_break_create($_POST['per_site'], $_GET['page'], $sql, 'shipping_status.php');
			  
			  $shipping_status = $query['query'];
			  $i=1;
			  while (!$shipping_status->EOF) {
			    if (((!$_GET['oID']) || ($_GET['oID'] == $shipping_status->fields['shipping_status_id'])) && (!$oInfo) && (substr($_GET['action'], 0, 3) != 'new')) {
			      $oInfo = new objectInfo($shipping_status->fields);
			    }
				if ($i % 2 == 0)
					$f = 'dataTableRow';
				else
					$f = '';
			    if ( (is_object($oInfo)) && ($shipping_status->fields['shipping_status_id'] == $oInfo->shipping_status_id) ) {
			      echo '<tr class="dataTableRowSelected" onmouseover="this.style.cursor=\'pointer\'" onclick="document.location.href=\''.href_link(FILENAME_SHIPPING_STATUS, (isset($_GET['page']) ? 'page='.$_GET['page'] : '').'&oID='.$oInfo->shipping_status_id.'&action=edit').'\'">'."\n";
			    } else {
			      echo '<tr class="'.$f.'" onmouseover="this.className=\'dataTableRowOver\';this.style.cursor=\'pointer\'" onmouseout="this.className=\''.$f.'\'" onclick="document.location.href=\''.href_link(FILENAME_SHIPPING_STATUS, (isset($_GET['page']) ? 'page='.$_GET['page'] : '').'&oID='.$shipping_status->fields['shipping_status_id']).'\'">'."\n";
			    }
			
				if (DEFAULT_SHIPPING_STATUS_ID == $shipping_status->fields['shipping_status_id']) {
					echo '<td class="dataTableContent" align="center">';
					if ($shipping_status->fields['shipping_status_image'] != '')
						echo '<img src="../images/'.$shipping_status->fields['shipping_status_image'].'" alt="" />';
					else 
						echo '-';
					echo '</td>';
					echo '<td class="dataTableContent"><b>'.$shipping_status->fields['shipping_status_name'].' ('.TEXT_DEFAULT.')</b></td>'."\n";
					
				} else {
      				echo '<td class="dataTableContent last" align="center">';
					if ($shipping_status->fields['shipping_status_image'] != '') {
						echo '<img src="../images/'.$shipping_status->fields['shipping_status_image'].'" alt="" />';
					} else 
						echo '-';
					echo '</td><td class="dataTableContent">'.$shipping_status->fields['shipping_status_name'].'</td>'."\n";
				}
				?>
                <td class="dataTableContent" align="right"><?php if ( (is_object($oInfo)) && ($shipping_status->fields['shipping_status_id'] == $oInfo->shipping_status_id) ) { echo image(DIR_WS_IMAGES.'icon_arrow_right.gif', ''); } else { echo '<a href="'.href_link(FILENAME_SHIPPING_STATUS, (isset($_GET['page']) ? 'page='.$_GET['page'] : '').'&oID='.$shipping_status->fields['shipping_status_id']).'">'.image(DIR_WS_IMAGES.'icon_info.gif', IMAGE_ICON_INFO).'</a>'; } ?>&nbsp;</td>
			<?php
				$i++;	echo '</tr>';
				$shipping_status->MoveNext();
			  }
			?>
            </table>
            <table border="0" width="100%" cellspacing="0" cellpadding="2">
              <tr class="page_break">
					<td class="smallText" valign="top" width="33.3%"><?php echo 'Angezeigt werden '.$query['from'].' bis '.$query['to'].' (von insgesamt '.$query['total'].' Status)'; ?></td>
					<td class="smallText" align="center" width="33.3%"></td>
					<td class="smallText" align="right" width="33.3%">
						Status pro Seite: <?php echo $query['page_break']->perSiteDropdown($_GET['page']); ?>
					</td>
				</tr>
				<tr><td align="center" colspan="3"><?php echo '<br />'.$query['links']; ?></td></tr>
			<?php
			  if (substr($_GET['action'], 0, 3) != 'new') {
			?>
              <tr>
                <td colspan="2" align="right"><?php echo '<a class="button" onclick="this.blur();" href="'.href_link(FILENAME_SHIPPING_STATUS, (isset($_GET['page']) ? 'page='.$_GET['page'] : '').'&action=new').'">'.BUTTON_INSERT.'</a>'; ?></td>
              </tr>
			<?php
			  }
			?>
            </table>
            </td>
			<?php
			  $heading = array();
			  $contents = array();
			  switch ($_GET['action']) {
			    case 'new':
			      $heading[] = array('text' => '<b>'.TEXT_INFO_HEADING_NEW_SHIPPING_STATUS.'</b>');
			
			      $contents = array('form' => draw_form('status', FILENAME_SHIPPING_STATUS, (isset($_GET['page']) ? 'page='.$_GET['page'] : '').'&action=insert', 'post', 'enctype="multipart/form-data"'));
			      $contents[] = array('text' => TEXT_INFO_INSERT_INTRO);
			
			      $shipping_status_inputs_string = '';
			      $languages = get_languages();
			      for ($i = 0, $n = sizeof($languages); $i < $n; $i++) {
			        $shipping_status_inputs_string .= '<br />'.image(DIR_WS_LANGUAGES.$languages[$i]['directory'].'/admin/images/'.$languages[$i]['image']).'&nbsp;'.draw_input_field('shipping_status_name['.$languages[$i]['id'].']');
			      }
			      $contents[] = array('text' => '<br />'.TEXT_INFO_SHIPPING_STATUS_IMAGE.'<br />'.draw_file_field('shipping_status_image', false));
			      $contents[] = array('text' => '<br />'.TEXT_INFO_SHIPPING_STATUS_NAME.$shipping_status_inputs_string);
			      $contents[] = array('text' => '<br />'.draw_checkbox_field('default').' '.TEXT_SET_DEFAULT);
			      $contents[] = array('align' => 'center', 'text' => '<br /><input type="submit" class="button" onclick="this.blur();" value="'.BUTTON_INSERT.'"/> <a class="button" onclick="this.blur();" href="'.href_link(FILENAME_SHIPPING_STATUS, (isset($_GET['page']) ? 'page='.$_GET['page'] : '')).'">'.BUTTON_CANCEL.'</a>');
			      break;
			
			    case 'edit':
			      $heading[] = array('text' => '<b>'.TEXT_INFO_HEADING_EDIT_SHIPPING_STATUS.'</b>');
			
			      $contents = array('form' => draw_form('status', FILENAME_SHIPPING_STATUS, (isset($_GET['page']) ? 'page='.$_GET['page'] : '').'&oID='.$oInfo->shipping_status_id .'&action=save', 'post', 'enctype="multipart/form-data"'));
			      $contents[] = array('text' => TEXT_INFO_EDIT_INTRO);
			
			      $shipping_status_inputs_string = '';
			      $languages = get_languages();
			      for ($i = 0, $n = sizeof($languages); $i < $n; $i++) {
			        $shipping_status_inputs_string .= '<br />'.image(DIR_WS_LANGUAGES.$languages[$i]['directory'].'/admin/images/'.$languages[$i]['image']).'&nbsp;'.draw_input_field('shipping_status_name['.$languages[$i]['id'].']', get_shipping_status_name($oInfo->shipping_status_id, $languages[$i]['id']));
			      }
			      $contents[] = array('text' => '<br />'.TEXT_INFO_SHIPPING_STATUS_IMAGE.'<br />'.draw_file_field('shipping_status_image'));
			      $contents[] = array('text' => '<br />'.TEXT_INFO_SHIPPING_STATUS_NAME.$shipping_status_inputs_string);
			      if (DEFAULT_SHIPPING_STATUS_ID != $oInfo->shipping_status_id) $contents[] = array('text' => '<br />'.draw_checkbox_field('default').' '.TEXT_SET_DEFAULT);
			      $contents[] = array('align' => 'center', 'text' => '<br /><button type="submit" class="button" onclick="this.blur();">'.BUTTON_UPDATE.'</button> <a class="button" onclick="this.blur();" href="'.href_link(FILENAME_SHIPPING_STATUS, (isset($_GET['page']) ? 'page='.$_GET['page'] : '').'&oID='.$oInfo->shipping_status_id).'">'.BUTTON_CANCEL.'</a>');
			      break;
			
			    case 'delete':
			      $heading[] = array('text' => '<b>'.TEXT_INFO_HEADING_DELETE_SHIPPING_STATUS.'</b>');
			
			      $contents = array('form' => draw_form('status', FILENAME_SHIPPING_STATUS, (isset($_GET['page']) ? 'page='.$_GET['page'] : '').'&oID='.$oInfo->shipping_status_id .'&action=deleteconfirm'));
			      $contents[] = array('text' => TEXT_INFO_DELETE_INTRO);
			      $contents[] = array('text' => '<br /><b>'.$oInfo->shipping_status_name.'</b>');
			      if ($remove_status) $contents[] = array('align' => 'center', 'text' => '<br /><input type="submit" class="button" onclick="this.blur();" value="'.BUTTON_DELETE.'"/> <a class="button" onclick="this.blur();" href="'.href_link(FILENAME_SHIPPING_STATUS, (isset($_GET['page']) ? 'page='.$_GET['page'] : '').'&oID='.$oInfo->shipping_status_id).'">'.BUTTON_CANCEL.'</a>');
			      break;
			
			    default:
			      if (is_object($oInfo)) {
			        $heading[] = array('text' => '<b>'.$oInfo->shipping_status_name.'</b>');
			
			        $contents[] = array('align' => 'center', 'text' => '<br /><a class="button" onclick="this.blur();" href="'.href_link(FILENAME_SHIPPING_STATUS, (isset($_GET['page']) ? 'page='.$_GET['page'] : '').'&oID='.$oInfo->shipping_status_id.'&action=edit').'">'.BUTTON_EDIT.'</a> <a class="button" onclick="this.blur();" href="'.href_link(FILENAME_SHIPPING_STATUS, (isset($_GET['page']) ? 'page='.$_GET['page'] : '').'&oID='.$oInfo->shipping_status_id.'&action=delete').'">'.BUTTON_DELETE.'</a>');
			
			        $shipping_status_inputs_string = '';
			        $languages = get_languages();
			        for ($i = 0, $n = sizeof($languages); $i < $n; $i++) {
			          $shipping_status_inputs_string .= '<br />'.image(DIR_WS_LANGUAGES.$languages[$i]['directory'].'/admin/images/'.$languages[$i]['image']).'&nbsp;'.get_shipping_status_name($oInfo->shipping_status_id, $languages[$i]['id']);
			        }
			
			        $contents[] = array('text' => $shipping_status_inputs_string);
			      }
			      break;
			  }
			
			  if ( (not_null($heading)) && (not_null($contents)) ) {
			    echo '<td width="25%" class="border" valign="top">'."\n";
			    $box = new box;
			    echo $box->infoBox($heading, $contents);	
			    echo '</td>'."\n";
			  }
			?>
          </tr>
        </table></td>
      </tr>
    </table></td>
  </tr>
</table>
</div>
<?php require(DIR_WS_INCLUDES.'footer.php'); ?>
</body>
</html>
<?php require(DIR_WS_INCLUDES.'application_bottom.php'); ?>